package lipengfei.botaiframework.security.jwt.authentication.impl;
import com.auth0.jwt.JWT;
import com.auth0.jwt.exceptions.JWTDecodeException;
import com.auth0.jwt.interfaces.DecodedJWT;

import lipengfei.botaiframework.jwt.JwtProperties;
import lipengfei.botaiframework.jwt.JwtUtil;
import lipengfei.botaiframework.security.jwt.authentication.JWTAuthenticationManager;
import lipengfei.botaiframework.security.jwt.properties.JwtTokenProperties;
import lipengfei.botaiframework.security.jwt.validator.ValidationResult;
import lipengfei.botaiframework.security.jwt.validator.Validator;
import lipengfei.botaiframework.security.jwt.validator.ValidatorModel;
import lipengfei.botaiframework.security.jwt.validator.eunm.ValidationState;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


public class AssignTokenAuthenticationManager implements JWTAuthenticationManager {

  
    private List<Validator<ValidatorModel>> validators = new ArrayList<Validator<ValidatorModel>>();

    public AssignTokenAuthenticationManager(List<Validator<ValidatorModel>> validators) {
        this.validators = validators;
    }

    public AssignTokenAuthenticationManager(Validator<ValidatorModel>... validators) {
        this.validators = Arrays.asList(validators);
    }

    public ValidationResult validate(ValidatorModel validatorModel) {

        for (Validator<ValidatorModel> validator : validators) {
            ValidationResult validationResult = validator.validate(validatorModel);
            if(validationResult!=null) {
            	  return validationResult;
            }
        }

        return new ValidationResult(true, ValidationState.SUCCESS);
    }
}